<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText"></block>
			<block slot="content" >收货地址</block>
		</cu-custom>
		<view class="qui-cells bg-transparent mt10">
			<view class="qui-cell bg-white mb15" v-for="(item, index) in CneeAddress" :key="index">
				<view class="cell-hd"><text :class="(item.IsDef==1?'bg-main':'bg-green')+' text-white cu-avatar round fs28'" v-text="item.CneeUser.substring(0,1)"></text></view>
				<view class="cell-bd" v-on:tap="selectAddress(item)">
					<view class="flex align-center">
						<text class="fs30 fw600" v-text="item.CneeUser"></text>
						<text class="ml20 fs30" v-text="item.Phone.substring(0,3)+'*****'+item.Phone.substring(item.Phone.length-4,4)"></text>

						<text class="cu-tag bg-main tag-1 plr15 ml20" v-if="item.IsDef==1">默认</text>
						<text class="cu-tag bg-color1 tag-1" v-if="item.Tag!=null" v-text="item.Tag"></text>
					</view>
					<view class="text-muted fs24 uni-ellipsis" style="width: 550upx;" v-text="item.Province+item.City+item.District+item.Address"></view>
				</view>
				<navigator :url="'/pages/my/setting/editAddress?act=edit&id='+item.CneeID" class="cell-ft">
					<image :src="imgurl + 'icon_edit_2.png'" mode="" class="img30"></image>
				</navigator>
			</view>
		</view>
		<view class="uni-btns_fixed-bottom ptb10">
			<navigator url="/pages/my/setting/editAddress?act=add&id=0" class="uni-btn flex align-center justify-center">
				<image :src="imgurl + 'icon_add.png'" mode="" class="img30"></image>
				<text class="fs28 fw600 ml10">添加收货地址</text>
			</navigator>
		</view>
	</view>
</template>

<script>
	import base from 'utils/base.js';
	import tools from 'utils/tools.js';
	export default {
		data() {
			return {
				CneeAddress: [],
				imgurl: this.$imgurl,
				businesstype: null
			};
		},
		onLoad(options) {
			let _self = this;
			_self.businesstype = options.businesstype;
		},
		onShow: function() {
			
			let time = 0;
				let globalData = getApp().globalData;
			let current = this;
			let si = setInterval(function() {
				time = time + 1;
				if (globalData.ticket) {
					current.GetCneeAddress();
					clearInterval(si);
				}
				if (time > 40) clearInterval(si);
			}, 200);
			
		},
		methods: {
			GetCneeAddress: function() {
				let currentPage = this;
				let params = {
					hideLoading: true,
					type: 'GET',
					url: '/api/CneeAddress/GetCneeAddressAllList',
					data: {},
					sCallback: function(response) {
						if (response.IsSuccess) {
							let list = response.Data;
							currentPage.CneeAddress = list;
						}
					}
				};
				base.request(params);
			},
			selectAddress: function(item) {
				let _this = this;
				if (_this.businesstype) {
					// var pages = getCurrentPages();
					// var prevPage = pages[pages.length - 2];
					// prevPage.Address = item
					
					uni.showModal({
						confirmColor: '#ff5e1f',
						title: '提示',
						content: '确定使用该收货地址吗',
						success: function(res) {
							if (res.confirm) {
								//获取用户信息
								var req = {
									"ActivityPrizeHistoryId": tools.getQueryVariable("activityprizehistoryid") || 0,
									"UserId": item.UserId,
									"UserName": item.CneeUser,
									"MobilePhone": item.Phone,
									"Province": item.Province,
									"City": item.City,
									"District": item.District,
									"Details": item.CneeAddr
								};
								let params = {
									type: 'POST',
									url: '/Activity/SaveAddress',
									data: req,
									sCallback: function(response) {
										if (response.Success) {
											uni.navigateBack({
												delta: 1
											});
										}
										else
											uni.showToast({
												icon: 'none',
												title: response.Msg
											});
									}
								};
								base.ActivityRequest(params);
							}
						}
					});
				}

			}
		},
		mounted() {}
	};
</script>

<style lang="scss" scoped>
	.tag-1 {
		display: inline-block;
		height: 35upx;
		line-height: 35upx;
		font-size: 20upx;
		border-radius: 10upx;
		color: #ffffff;
	}

	.bg-color1 {
		background-image: linear-gradient(#6a83d7, #6a83d7), linear-gradient(#ffffff, #ffffff);
	}
</style>
